/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package co.edu.univalle.proyecto.persistencia;

import co.edu.univalle.proyecto.modelo.Formatos;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author CQ 43 - 450LA
 */
@Stateless
public class FormatosDAO implements FormatosDAOLocal {
 @PersistenceContext
    private EntityManager entityManager;
 
    @Override
    public void registrar(Formatos formato) {
        try{
            entityManager.persist(formato);
        }catch(RuntimeException e){
            throw e;
                }
    }

    @Override
    public void eliminar(Formatos formato) {
        try{
            entityManager.remove(formato);
        }catch(RuntimeException e){
            throw e;
        
        }  
    }

    @Override
    public void modificar(Formatos formato) {
     try{
            entityManager.merge(formato);
        }catch(RuntimeException e){
            throw e;
        
        }
    }

    @Override
    public List<Formatos> consultar() {
         try{
            String jpql = "select f from Formatos f";
            Query query = entityManager.createQuery(jpql);
            return query.getResultList();
        }catch(RuntimeException e){
            throw e;
        
        }
    }

    @Override
    public Formatos consultarPorNombre(String nombre) {
      try{
            return entityManager.find(Formatos.class, nombre);
        }catch(RuntimeException e){
            throw e;
        
        }
    }

    @Override
    public List<Formatos> consultarFormatosPorProceso(String proceso) {
        try{
            String consulta = "select f from Formatos f where f.nombreProceso ="+proceso;
            Query query = entityManager.createQuery(consulta);
            return query.getResultList();
        }catch(RuntimeException e){
            throw e;
        
        }
    }

    
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
}
